package com.zxjbyte.yiyi.extension.job.enums;

import com.zxjbyte.yiyi.framework.common.core.ObjectArrayFactory;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 邮件报警类型枚举
 *
 * @Author zhangxingjia
 * @Date 2023/11/13 20:31
 * @Version: 1.0
 */
@AllArgsConstructor
public enum JobAlarmTypeEnum implements ObjectArrayFactory {
    // 执行任务超时
    TIMEOUT("执行任务超时"),

    // 异常
    EXCEPTION("执行任务异常");

    @Getter
    private final String desc;

    @Override
    public Object[] array() {
        return Arrays.stream(values()).map(JobAlarmTypeEnum::name).toArray(String[]::new);
    }

    /**
     * 是否存在
     * @param name
     * @return true 存在
     */
    public static boolean checkIsExist(String name){
        return Arrays.stream(values()).anyMatch(f -> f.name().equals(name));
    }

    public static JobAlarmTypeEnum get(String name){
        return Arrays.stream(values()).filter(f -> Objects.equals(f.name(), name)).findFirst().orElse(null);
    }

}
